package com.eurake.seckill.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor(force = true)
@AllArgsConstructor
public class RespBean {
    private final Integer code;
    private String msg;
    private final Object data;
    //成功返回结果
    public static RespBean success(){
        return new RespBean(RespBeanEnum.SUCCESS.getCode(),RespBeanEnum.SUCCESS.getMessage(),null);
    }
    public static RespBean success(Object data ){
        return new RespBean(RespBeanEnum.SUCCESS.getCode(),RespBeanEnum.SUCCESS.getMessage(),data);
    }
    public static RespBean error(RespBeanEnum respBeanEnum){
        //失败的原因很多，所以需要传入失败的枚举类
        return new RespBean(respBeanEnum.getCode(),respBeanEnum.getMessage(),null);
    }
    public static RespBean error(RespBeanEnum respBeanEnum,Object data){
        //失败的原因很多，所以需要传入失败的枚举类
        return new RespBean(respBeanEnum.getCode(),respBeanEnum.getMessage(),data);
    }
    public static RespBean error(Exception e){
        //其他系统异常
        return new RespBean(500,e.toString(),null);
    }
}
